home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3628 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: classic.iinet.com.au!news
  2. From: ng@mitswa.com.au (John A Ng)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: class declaration
  5. Date: Thu, 25 Jan 1996 02:09:54 GMT
  6. Organization: MITS (WA)
  7. Message-ID: <4e6ngs$f2d@classic.iinet.com.au>
  8. References: <4dphp6$1bp@noc2.drexel.edu> <4drakm$hnu@grid.direct.ca> <ALUN.CHAMPION.96Jan22114418@g7240065.bridge.bst.bls.com>
  9. NNTP-Posting-Host: grunge197.nv.iinet.net.au
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. >: st918h5w@dunx1.ocs.drexel.edu (Jonathan Juniman) wrote:
  13.  
  14. >:> Is it necessary to do this:
  15.  
  16. >:> class SomeClass
  17. >:>     {
  18. >:>     public:
  19. >:>     void Somefunction(int SomeParameter);
  20. >:>     }
  21.  
  22. >:> or is it just as legal to do this:
  23. >:> class SomeClass
  24. >:>     {
  25. >:>     public:
  26. >:>     void SomeFunction(int);
  27. >:>     }
  28.  
  29. >:> The latter seems to be the convention, but why does the compiler need to
  30. >:> know the name of SomeFunction's argument?  Isn't it sufficient to know the
  31. >:> type of Somefunction's argument (namely, int)?  
  32.  
  33.  
  34. The parameter variable name is ignored by the compiler.  You can either
  35. not put anything there, or you can have a (legal) variable name (whether
  36. the name IS or NOT the same as that actually defined in the body).  This
  37. is is allowed for not so much for documentation as for the convenience
  38. of being able to copy & paste between body and header declaration.
  39.  
  40. The typical thing is to leave the variable name in both body and header.
  41.  
  42. By the way, always remember the semi-colon at the end of the class
  43. definition... it can cause strange compilation errors!
  44.  
  45.  
  46.  
  47. >: The following will compile under Turbo C++ 3.00 -- I don't know what
  48. >: the standard is --
  49.  
  50. >: class foo
  51. >: {
  52. >:     public:
  53. >:     void bar (int);
  54. >: };
  55.  
  56. >: void foo::bar (int baz)
  57. >: {
  58. >:     // do someFoobar
  59. >:     ++baz;
  60. >: }
  61.  
  62. >: void main (void)
  63. >: {
  64. >:     foo Chocolate;
  65. >:     Chocolate.bar(10);
  66. >: }
  67.  
  68. There is absolutely nothing wrong with the above program -- not even
  69. style.
  70. Regards,
  71.  
  72. John Ng
  73. ng@mitswa.com.au
  74. Western Australia
  75.  
  76.